import Vue from 'vue'
import Vuex from 'vuex'
import http from '@/util/https'
Vue.use(Vuex)

export default new Vuex.Store({
  //state公共状态
  state: {
    cityId:'421100',
    cityName:'黄冈',
    cinemaList:[],
    isTabbarShow:true
  },
  //统一管理，被devtools记录状态的修改
  //只能支持同步
  mutations: {
    changeCityName(state,cityName){
      state.cityName = cityName
    },
    changeCityId(state,cityId){
      state.cityId = cityId
    },
    changesetCinemaData(state,data){
    state.cinemaList = data
    },
    clearCinema(state) {
      state.cinemaList = []
    },
    show (state) {
      state.isTabbarShow = true
    },
    hide (state) {
      state.isTabbarShow = false
    }
  },
  
  //支持同步和异步
  actions: {
    getCinemaData(store,cityId){
      // console.log('getCinemaData-action');
      return http({ 
        url:`/gateway?cityId=${cityId}&ticketFlag=1&k=4594973`,
        headers:{
            'X-Host':'mall.film-ticket.cinema.list'
        }
        }).then((res)=> {
            console.log(res.data.data.cinemas)
            store.commit("changesetCinemaData",res.data.data.cinemas)
        })
       
    }
  },
  modules: {
  }
})
